<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------

declare(strict_types=1);

namespace app\dynamic\info;

use app\dynamic\model\CardCompany;
use app\dynamic\model\CardTimeline;
use app\shop\model\IndexUserInfo;
use longbingcore\diy\BaseSubscribe;
use longbingcore\tools\LongbingDefault;

/**
 * @author shuixian
 * @DataTime: 2019/12/11 16:23
 * Class Subscribe
 * @package app\ucenter\info
 */
class Subscribe extends BaseSubscribe
{

    /**
     * 名片展示页获取其他模块数据
     *
     * @param $params
     * @return array
     * @author shuixian
     * @DataTime: 2019/12/24 14:24
     */
    public function onCardInfo($params)
    {
        //需要做一个开关开启三条动态
        $dynamic_list = [];

        $config = longbingGetAppConfig($this->_uniacid) ;
        
        if(isset($config['dynamic_switch']) && $config['dynamic_switch'] == 1) {


            $staff_id = $this->_param['staff_id'];
            $line = new CardTimeline();
            $userId = $this->getUserId();
            $diss = [];
            $dis = [];
            if ($staff_id) {
                $userinfo = new IndexUserInfo();
                $company_model = new CardCompany();
                $company_id = $userinfo->getCompanyId(['fans_id' => $staff_id]);
                $top_company = $company_model->topCompany($company_id);
                $diss['a.company_id'] = $top_company['id'];

                $diss['a.user_id'] = $staff_id;
                $dis['a.user_id'] = 0;
                $dis['a.company_id'] = 0;
                $dis['a.status'] = 1;
                $dis['a.uniacid'] = $this->_uniacid;
            } else {
                $where['a.user_id'] = $userId;
            }
            $where['a.uniacid'] = $this->_uniacid;
            $where['a.status'] = 1;

            $list = $line->dtlistv2(1, 3, $where, $staff_id, $userId, $dis, $diss);
            $list['data'] = LongbingDefault::formatDefaultImage($list['data'], 'avatarUrl', 'avatar', LongbingDefault::$avatarImgUrl);

            $dynamic_list = $list['data'];

        }

        return ['dynamic_list' => $dynamic_list];

    }

    /**
     * 相应个人中心工具菜单
     *
     * @return mixed
     * @author shuixian
     * @DataTime: 2019/12/12 11:24
     */
    public function onAddWorkCenterToolsMenu(){

        $permission =  new PermissionDynamic($this->_uniacid);

        if($permission->pAuth()){
            $toolsMenu= [
                "title" =>  '我的动态',
                "icon" =>  'icondongtai',
                "link" =>  '/admin/pages/info/list',
                "linkType" =>  '4',
            ];
            return [$toolsMenu];
        }

        return [];


    }



    /**
     * 监听代理管理端授权小程序事件
     *
     * @param $data
     * @return array
     * @author shuixian
     * @DataTime: 2019/12/27 17:33
     */
    public function onAgentAppAuthEdit($config){

        $permission = new PermissionDynamic(0);

        if($permission->sAuth() && $permission->infoConfig['auth_platform'] ) {

            $auth_switch['formType'] = 'radio';
            $auth_switch['name'] = 'timeline_switch';

            $auth_switch['value'] = $config ? $config[ $auth_switch['name'] ] : 0;
            $auth_switch['title'] = $permission->info['title'];

            return [ $auth_switch ];

        }

    }

}